<template>
  <div class="container">
    <el-card class="box-card" style="margin-top: 20px">
      <div slot="header" class="clearfix">
        <span>首诊咨询配置</span>
      </div>
      <div
        style="border: 1px solid #e5e5e5; border-radius: 15px; padding: 20px"
      >
        <el-form label-width="160px">
          <el-form-item label="首诊咨询状态">
            <el-row :span="24">
              <el-switch
                v-model="data.firstConsultationStatus"
                active-text="开启"
                inactive-text="关闭"
              ></el-switch>
            </el-row>
          </el-form-item>
          <el-form-item
            label="首诊咨询价格"
            v-if="data.firstConsultationStatus"
          >
            <el-row :span="24">
              <el-input
                type="number"
                v-model="data.firstConsultationPrice"
              ></el-input>
            </el-row>
          </el-form-item>
        </el-form>
        <el-row
          style="
            display: flex;
            width: 100%;
            align-items: center;
            justify-content: center;
          "
        >
          <el-button type="primary" @click="handleSubmit">确定</el-button>
        </el-row>
      </div>
    </el-card>
    <el-card class="box-card" style="margin-top: 20px">
      <div slot="header" class="clearfix">
        <span>团队问诊配置</span>
      </div>
      <div
        style="border: 1px solid #e5e5e5; border-radius: 15px; padding: 20px"
      >
        <el-form label-width="160px">
          <el-form-item label="团队问诊状态">
            <el-row :span="24">
              <el-switch
                v-model="data.firstConsultationStatus"
                active-text="开启"
                inactive-text="关闭"
              ></el-switch>
            </el-row>
          </el-form-item>
          <el-form-item
            label="团队问诊价格"
            v-if="data.firstConsultationStatus"
          >
            <el-row :span="24">
              <el-input
                type="number"
                v-model="data.firstConsultationPrice"
              ></el-input>
            </el-row>
          </el-form-item>
        </el-form>
        <el-row
          style="
            display: flex;
            width: 100%;
            align-items: center;
            justify-content: center;
          "
        >
          <el-button type="primary" @click="handleSubmit">确定</el-button>
        </el-row>
      </div>
    </el-card>
    <el-card class="box-card" style="margin-top: 20px">
      <div slot="header" class="clearfix">
        <span>MDT会诊配置</span>
      </div>
      <div
        style="border: 1px solid #e5e5e5; border-radius: 15px; padding: 20px"
      >
        <el-form label-width="160px">
          <el-form-item label="MDT会诊状态">
            <el-row :span="24">
              <el-switch
                v-model="data.firstConsultationStatus"
                active-text="开启"
                inactive-text="关闭"
              ></el-switch>
            </el-row>
          </el-form-item>
          <el-form-item label="MDT会诊价格" v-if="data.firstConsultationStatus">
            <el-row :span="24">
              <el-input
                type="number"
                v-model="data.firstConsultationPrice"
              ></el-input>
            </el-row>
          </el-form-item>
        </el-form>
        <el-row
          style="
            display: flex;
            width: 100%;
            align-items: center;
            justify-content: center;
          "
        >
          <el-button type="primary" @click="handleSubmit">确定</el-button>
        </el-row>
      </div>
    </el-card>

    <el-card class="box-card" style="margin-top: 20px">
      <div slot="header" class="clearfix">
        <span>快递费用设置</span>
      </div>
      <div
        style="border: 1px solid #e5e5e5; border-radius: 15px; padding: 20px"
      >
        <el-form label-width="160px">
          <el-form-item label="快递费用（元）">
            <el-row :span="24">
              <el-input
                type="number"
                :max="100"
                :min="0"
                v-model="courierFee"
              ></el-input>
            </el-row>
          </el-form-item>
        </el-form>
        <el-row
          style="
            display: flex;
            width: 100%;
            align-items: center;
            justify-content: center;
          "
        >
          <el-button type="primary" @click="setCourierFee">确定</el-button>
        </el-row>
      </div>
    </el-card>
  </div>
</template>

<script>
import { ApiGetConfig, ApiSetConfig } from "@a/index";
export default {
  components: {},
  data() {
    return {
      data: {
        firstConsultationStatus: false,
        firstConsultationPrice: 0,
      },
      courierFee: "",
    };
  },
  mounted() {
    this.getHospitalInfo();
  },
  methods: {
    getHospitalInfo() {
      let arr = [];
      ApiGetConfig({ key: "firstConsultation" }).then((res) => {
        let firstConsultation = {
          firstConsultationStatus: false,
          firstConsultationPrice: 0,
        };
        if (res.data) {
          try {
            firstConsultation = JSON.parse(res.data);
          } catch {
            firstConsultation = {
              firstConsultationStatus: false,
              firstConsultationPrice: 0,
            };
          }
        }
        this.data = firstConsultation;
      });

      ApiGetConfig({ key: "courierFee" }).then((res) => {
        if (res.data) {
          console.log(res.data);
          this.courierFee = res.data;
        }
      });
    },
    handleSubmit() {
      let param = {
        key: "firstConsultation",
        value: JSON.stringify(this.data),
      };
      ApiSetConfig(param).then((res) => {
        if (res.code == 200) {
          this.$message.success("保存成功");
        }
      });
    },
    //设置快递费
    setCourierFee() {
      let param = {
        key: "courierFee",
        value: this.courierFee,
      };
      ApiSetConfig(param).then((res) => {
        if (res.code == 200) {
          this.$message.success("保存成功");
        }
      });
    },
  },
};
</script>
<style scoped></style>
